<?php
namespace app\index\controller;
use QL\QueryList;
//use phpmailer\PHPMailer;
use app\index\model\Index as getModel;

class Index
{
    public function index()
    {
     return view('main'); //只能跳到html文件
    }

    public function test(){

        ini_set('max_execution_time', 600);
        //爬取的内容规则
        $indata = new getModel();
        for($i=1;$i<=140;$i++){
            $params = [
                'title'=>['.hover-box .e-title','text'],
                'imgUrl'=>["#eventAjaxLoad li a img",'src'],
                'pageUrl'=>["#eventAjaxLoad li a",'href'],
                'shoufa'=>['.img-box','html'],
                'tagList'=>['.e-tag-list','text'],
                'numLeft'=>['.e-number span.e-apply-number','text'],
                'numRight'=>['.e-number span.e-query','text'],
                'content'=>['.e-item-hide','text']
            ];
            //http://www.jiguo.com/product/index/type/2/page/175.html
            $ql = QueryList::Query('http://www.jiguo.com/event/index/page/'.$i.'/act/index.html',$params);
            $data = $ql->data;
            $j = 0;
           while($j<count($data)) {
               $data[$j]['shoufa'] = strip_tags($data[$j]['shoufa']);
               $data[$j]['tagList'] = Index::changeStr($data[$j]['tagList']);
               $data[$j]['content'] = Index::changeStr($data[$j]['content']);
               $j++;
           }
            $indata->saveAll($data);
        }
    }

    public function mail(){
        $mail = new PHPMailer();
        //配置发送邮件的操作
        print_r($mail);
    }

    public function check(){
        return view('check');

    }

    public function tryGoods(){
        return view ('tryGoods');
    }

    public function newGoods(){
        return view ('newGoods');
    }

//    public function test(){
//        return md5('WT18'.md5(123456));
//    }

    public function checks(){
        return view('test');
    }

    static function changeStr($str){
        $str = str_replace(' ','',$str);
        $str = str_replace(array("\n"),'a',$str);
        $str = preg_replace('/a{1,}/','#',$str);
        return $str;
    }
}
